package com.zsy.petshop_01.service.impl;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.model.entity.Discount;
import com.zsy.petshop_01.model.vo.discount.InsertVo;
import com.zsy.petshop_01.model.vo.discount.UpdateVo;
import com.zsy.petshop_01.manager.DiscountManager;
import com.zsy.petshop_01.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DiscountServiceImpl implements DiscountService {
    @Autowired
    DiscountManager discountManager;

    @Override
    public ResponseResult<?> selectAll() {
        List<Discount> discounts = discountManager.selectAll();
        return ResponseResult.success("OK", discounts);
    }

    @Override
    public ResponseResult<?> selectByMessage(String message) {
        List<Discount> discounts = new ArrayList<>();
        if(message!=null) {
            discounts = discountManager.selectByMessage(message);
        }else{
            discounts = discountManager.selectAll();
        }
        return ResponseResult.success("OK", discounts);
    }

    @Override
    public ResponseResult<?> insert(InsertVo insertVo) {
        discountManager.insert(insertVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> update(UpdateVo updateVo) {
        discountManager.update(updateVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> delete(Integer id) {
        discountManager.delete(id);
        return ResponseResult.success("OK");
    }
}

